<?php
error_reporting(E_ALL ^ E_NOTICE); //Desactivo los mensajes de error
require_once "../includes/objects.php";
?>
<!DOCTYPE html>
<html lang="es">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>Stick WARS - APP</title>
		<link rel="stylesheet" href="jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.css" />
		<link rel="stylesheet" href="./css/style.css" />
		<script src="../js/jquery-1.8.2.js"></script>
		<script src="jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"></script>
		<script src="./js/login-logout.js"></script>
		<script src="./js/rank.js"></script>
	</head>
	<body>
		<script type="text/javascript">
		$(document).bind("pageinit", function() {
			//$.mobile.defaultPageTransition = "slide";
			$.mobile.loader.prototype.options.text = "Cargando...";
  			$.mobile.loader.prototype.options.textVisible = true;
  			$.mobile.loader.prototype.options.theme = "a";
  			$.mobile.loader.prototype.options.html = "";
		});
		</script>
		
		<?php require_once "./includes/loadSession.php"; ?>
		
		<!-- PERFIL -->
		<div id="perfil" data-role="page" class="img-background">
			<!--  HEADER -->
			<div data-role="header" data-id="persistent" data-position="fixed">
				<a href="#perfil" data-role="button" data-inline="true" data-icon="arrow-l" data-iconpos="notext"></a>
				<h1>Perfil</h1>
				<button id="forward" data-inline="true" data-icon="arrow-r" data-iconpos="notext"></button>
				<!-- NAVBAR -->
				<div data-role="navbar">
					<ul>
						<li><a href="#perfil" class="ui-btn-active ui-state-persist" data-inline="true" data-role="button" data-icon="home" data-theme="a" data-iconpos="top">Perfil</a></li>
						<li><a href="#edificios" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Edificios</a></li>
						<li><a href="#tropas" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Tropas</a></li>
						<li><a href="#rank"data-transition="slide" data-inline="true" data-role="button" data-icon="search" data-theme="a"  data-iconpos="top">Rank</a></li>
						<li><a data-inline="true" data-role="button" data-icon="delete" data-theme="a"  data-iconpos="top" class="btn-logout">Log out</a></li>
					</ul>
				</div>
				<!-- FIN NAVBAR -->
			</div>
			<div class="gradient-navbar"></div>
			<!-- FIN HEADER -->
			
			<!--LOGIN -->
			<?php
			require"./containers/check-login.php";

			if($isLogged){
				
				//mostrar perfil de usuario pinchado en ranking
			$usuario_busqueda=$_GET['user'];
			
			
				if(isset($usuario_busqueda)){
					$id_us=User::getUserId ($usuario_busqueda);
					$estadisticas=new Estadisticas($id_us);
					$usuario=new User($usuario_busqueda);
					
					if($usuario->avatar=="./avatares/default.png"){
					$usuario->avatar=".".$usuario->avatar;

				}
				echo "<div data-role='content'>";
					echo '<div class="login-box white-background">';
						echo '<img class="avatar avatar_mobile" src="'.$usuario->avatar.'" alt="no se pudo cargar la imagen"/><br/>';
						echo '<span class="nombre_mobile">'.$usuario->nombre."</span><br/><br/>";						
						echo '<br/><center><table class="tabla_victorias"><tr><td><span class="texto_perfil">Puntuación</span></td></tr><tr><td><span class="victoriaderrota">' .$estadisticas->rank. '</span></td></tr></table></center>';
						echo '<br/><center><table class="tabla_victorias"><tr><td><span class="texto_perfil">Victorias</span></td><td></td><td><span class="texto_perfil">Derrotas</span></td></tr>';			
						echo '<tr><td><center><span class="victoriaderrota">' .$estadisticas->victorias.'</span></h1></center></td><td><span class="victoriaderrota">-</span></td><td><center><span class="victoriaderrota">' .$estadisticas->derrotas.'</span></center></td></tr></table></center>';
						
						
						
						echo '<b>Ultima actualizacion: </b>' .$estadisticas->last_update->format("d/m/y g:i:s A"). "</br>";
										echo '<a href="index.php" class="ui-btn-active ui-state-persist" data-inline="true" data-role="button" data-icon="home" data-theme="b" data-iconpos="left">Volver a mi perfil</a>';
					echo '</div>';
				echo '</div>';
				
				
				
					//termina mostrar perfil de usuario pinchado en rankin
					
				}else{
			

				//CONTENIDO
					if($usuario->avatar=="./avatares/default.png"){
					$usuario->avatar=".".$usuario->avatar;

				}
				echo "<div data-role='content'>";
					echo '<div class="login-box white-background">';
						echo '<img class="avatar avatar_mobile" src="'.$usuario->avatar.'" alt="no se pudo cargar la imagen"/><br/>';
						echo '<span class="nombre_mobile">'.$usuario->nombre."</span><br/><br/>";
						echo '<br/><center><table class="tabla_victorias"><tr><td><span class="texto_perfil">Puntuación</span></td></tr><tr><td><span class="victoriaderrota">' .$estadisticas->rank. '</span></td></tr></table></center>';
						echo '<br/><center><table class="tabla_victorias"><tr><td><span class="texto_perfil">Victorias</span></td><td></td><td><span class="texto_perfil">Derrotas</span></td></tr>';			
						echo '<br/><tr><td><center><span class="victoriaderrota">' .$estadisticas->victorias.'</span></h1></center></td><td><span class="victoriaderrota">-</span></td><td><center><span class="victoriaderrota">' .$estadisticas->derrotas.'</span></center></td></tr></table></center>';
						
						echo '<br/><center><table class="tabla_victorias"><tr><td><span class="tabla_victorias">Carbón</span></td><td></td><td><span class="tabla_victorias">Plástico</span></td></tr>';			
						echo '<tr><td><img width="32px" src="../img/carbon2.png"/> <span class="texto_recursos">' .$estadisticas->carbon.'</span></td><td><span class="texto_recursos"> </span></td><td><img width="32px" src="../img/plastico2.png"/> <span class="texto_recursos">' .$estadisticas->plastico.'</span></td></tr></table></center>';
						
						
						echo '<br/><b>Email: </b>' .$usuario->email. "</br><p/>";
						echo '<b>Administrador: </b>' .$usuario->admin. "</br>";
						echo '<p><b>Ultima actualizacion: </b>' .$estadisticas->last_update->format("d/m/y g:i:s A"). "</p></br>";
					echo '</div>';
				echo '</div>';
			}
			}
			?>
		</div>
		<!-- FIN PERFIL -->
		
		
			
		
		<!-- EDIFICIOS -->
		<div id="edificios" data-role="page" class="img-background">
			<!--  HEADER -->
			<div data-role="header" data-id="persistent" data-position="fixed">
				<a href="#perfil" data-role="button" data-inline="true" data-icon="arrow-l" data-iconpos="notext"></a>
				<h1>Edificios</h1>
				<button id="forward" data-inline="true" data-icon="arrow-r" data-iconpos="notext"></button>
				<!-- NAVBAR -->
				<div data-role="navbar">
					<ul>
						<li><a href="#perfil" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="home" data-theme="a" data-iconpos="top">Perfil</a></li>
						<li><a href="#edificios" class="ui-btn-active ui-state-persist" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Edificios</a></li>
						<li><a href="#tropas" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Tropas</a></li>
						<li><a href="#rank" data-transition="slide" data-inline="true" data-role="button" data-icon="search" data-theme="a"  data-iconpos="top">Rank</a></li>
						<li><a data-inline="true" data-role="button" data-icon="delete" data-theme="a"  data-iconpos="top" class="btn-logout">Log out</a></li>
					</ul>
				</div>
				<!-- FIN NAVBAR -->
			</div>
			<div class="gradient-navbar"></div>
			<!-- FIN HEADER -->
			
			<!-- LOGIN -->
			<?php
			require"./containers/check-login.php";
			if($isLogged){
				require_once "./containers/build-list.php";
			}
			?>
		</div>
		<!-- FIN EDIFICIOS -->
		
		<!-- TROPAS -->
		<div id="tropas" data-role="page" class="img-background">
			<!--  HEADER -->
			<div data-role="header" data-id="persistent" data-position="fixed">
				<a href="#perfil" data-role="button" data-inline="true" data-icon="arrow-l" data-iconpos="notext"></a>
				<h1>Tropas</h1>
				<button id="forward" data-inline="true" data-icon="arrow-r" data-iconpos="notext"></button>
				<!-- NAVBAR -->
				<div data-role="navbar">
					<ul>
						<li><a href="#perfil" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="home" data-theme="a" data-iconpos="top">Perfil</a></li>
						<li><a href="#edificios" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Edificios</a></li>
						<li><a href="#tropas" class="ui-btn-active ui-state-persist" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Tropas</a></li>
						<li><a href="#rank" data-transition="slide" data-inline="true" data-role="button" data-icon="search" data-theme="a"  data-iconpos="top">Rank</a></li>
						<li><a data-inline="true" data-role="button" data-icon="delete" data-theme="a"  data-iconpos="top" class="btn-logout">Log out</a></li>
					</ul>
				</div>
				<!-- FIN NAVBAR -->
			</div>
			<div class="gradient-navbar"></div>
			<!-- FIN HEADER -->
			
			<!-- LOGIN -->
			<?php
			require"./containers/check-login.php";
			if($isLogged){
				require_once "./containers/army-list.php";
			}
			?>
			
			<!-- CONTENIDO -->
			
			<div data-role="content">
				
			</div>
		</div>
		<!-- FIN TROPAS -->
		
		<!-- RANK -->
		<div id="rank" data-role="page" class="img-background">
			<div data-role="header" data-id="persistent" data-position="fixed">
				<a href="#perfil" data-role="button" data-inline="true" data-icon="arrow-l" data-iconpos="notext"></a>
				<h1>Ranking</h1>
				<button id="forward" data-inline="true" data-icon="arrow-r" data-iconpos="notext"></button>
				<!-- NAVBAR -->
				<div data-role="navbar">
					<ul>
						<li><a href="#perfil" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="home" data-theme="a" data-iconpos="top">Perfil</a></li>
						<li><a href="#edificios" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Edificios</a></li>
						<li><a href="#tropas" data-direction="reverse" data-transition="slide" data-inline="true" data-role="button" data-icon="plus" data-theme="a" data-iconpos="top">Tropas</a></li>
						<li><a href="#rank" data-direction="reverse" data-transition="slide" class="ui-btn-active ui-state-persist" data-inline="true" data-role="button" data-icon="search" data-theme="a"  data-iconpos="top">Rank</a></li>
						<li><a data-inline="true" data-role="button" data-icon="delete" data-theme="a"  data-iconpos="top" class="btn-logout">Log out</a></li>
					</ul>
				</div>
				<!-- FIN NAVBAR -->
			</div>
			<div class="gradient-navbar"></div>
			<!-- FIN HEADER -->
			
			<!-- LOGIN -->
			<?php
			require"./containers/check-login.php";
			if($isLogged){
			?>
			<!-- CONTENIDO -->
				
				<div data-role="content">
					<div class="login-box white-background">
						<div class="ui-grid-a">
							<div class="ui-block-a doble"><input type="text" id="rank-search-input" /></div>
							<div class="ui-block-b doble" id="rank-search-btn"><button data-icon="search" data-iconpos="right" data-theme="a">Ir</button></div>
						</div>
						</br>
						<ul data-role="listview" id="rank-list">
							<!-- AJAX LOADED LIST -->
						</ul>
						<!-- NAVEGADOR -->
						</br>
						<div class="fixed-bottom ui-grid-a">
							<div id="rank-anterior" class="ui-block-a"><button data-icon="arrow-l" data-theme="a">Anterior</button></div>
							<div id="rank-siguiente" class="ui-block-b"><button data-icon="arrow-r" data-iconpos="right" data-theme="a">Siguiente</button></div>
						</div>
					</div>
				</div>
				
				
			<?php
			}
			?>
			
		</div>
		<!-- FIN RANK -->
		
	</body>
</html>